
layui.use(['layer','table','laydate'],function(){
    $ = layui.jquery;
    var layer = layui.layer ,table = layui.table,laydate = layui.laydate;
    //第一个实例
    table.render({
        elem: '#demo'
        ,height: "auto"
        ,method:"post"
        ,url: baseUrl+'money/findList' //数据接口
        ,page: false //开启分页
        ,where : {gameType:0}
        ,cols: [[ //表头
             {field: 'id', title: 'id',align:'center', sort:true}
            ,{field: 'money1', title: '筹码1',align:'center',event:"edit1"}
            ,{field: 'money2', title: '筹码2',align:'center',event:"edit2"}
            ,{field: 'money3', title: '筹码3',align:'center',event:"edit3"}
            ,{field: 'money4', title: '筹码4',align:'center',event:"edit4"}
            ,{field: 'money5', title: '筹码5',align:'center',event:"edit5"}
            ,{field: 'money6', title: '筹码6',align:'center',event:"edit6"}
            ,{field: 'roomGrade', title: '房间级别',align:'center',templet:function (d) {
                    if(d.roomGrade == 0){
                        return "<span style='color: #1E9FFF'>初级场</span>";
                    }else if (d.roomGrade ==1) {
                        return "<span style='color: #1E9FFF'>中级场</span>";
                    }else if (d.roomGrade ==2) {
                        return "<span style='color: #1E9FFF'>高级场</span>";
                    }
                }}
        ]]
        ,done:function(res,curr,count){
            // 隐藏列
            $(".layui-table-box").find("[data-field='id']").css("display","none");
        }
    });
    //监听工具条
    table.on('tool(test)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr; //获得当前行 tr 的DOM对象
         if(layEvent === 'edit1') { //编辑
           layer.prompt({
               formType: 2
               ,shadeClose:true
               ,title: '筹码'
               ,value: data.money1
           }, function(value, index){
               if (isNaN(value)) {
                   layer.msg("请输入数字！");
                   return;
               }
               layer.close(index);
               var uinfo = { "money1" : value,"id":data.id }
               //这里一般是发送修改的Ajax请求
               $.ajax({
                   type: 'post',
                   url: baseUrl+"money/update",
                   data: uinfo,
                   async:false,
                   dataType: 'json',
                   success: function(res){
                       if(res.meta.code==200){
                           //加载层
                           var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                           setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                           setTimeout(function(){
                               obj.update({
                                   money1: value
                               });}, 1000);
                       }else{
                           //加载层
                           var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                           setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                       }
                   }
               });
           });
       }else if(layEvent === 'edit2') { //编辑
           layer.prompt({
               formType: 2
               ,shadeClose:true
               ,title: '筹码'
               ,value: data.money2
           }, function(value, index){
               if (isNaN(value)) {
                   layer.msg("请输入数字！");
                   return;
               }
               layer.close(index);
               var uinfo = { "money2" : value,"id":data.id }
               //这里一般是发送修改的Ajax请求
               $.ajax({
                   type: 'post',
                   url: baseUrl+"money/update",
                   data: uinfo,
                   async:false,
                   dataType: 'json',
                   success: function(res){
                       if(res.meta.code==200){
                           //加载层
                           var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                           setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                           setTimeout(function(){
                               obj.update({
                                   money2: value
                               });}, 1000);
                       }else{
                           //加载层
                           var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                           setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                       }
                   }
               });
           });
       }else if(layEvent === 'edit3') { //编辑
             layer.prompt({
                 formType: 2
                 ,shadeClose:true
                 ,title: '请输出最低上庄金币'
                 ,value: data.money3
             }, function(value, index){
                 if (isNaN(value)) {
                     layer.msg("请输入数字！");
                     return;
                 }
                 layer.close(index);
                 var uinfo = { "money3" : value,"id":data.id }
                 //这里一般是发送修改的Ajax请求
                 $.ajax({
                     type: 'post',
                     url: baseUrl+"money/update",
                     data: uinfo,
                     async:false,
                     dataType: 'json',
                     success: function(res){
                         if(res.meta.code==200){
                             //加载层
                             var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                             setTimeout(function(){
                                 obj.update({
                                     money3: value
                                 });}, 1000);
                         }else{
                             //加载层
                             var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                         }
                     }
                 });
             });
         }else if(layEvent === 'edit4') { //编辑
             layer.prompt({
                 formType: 2
                 ,shadeClose:true
                 ,title: '请输出最低上庄金币'
                 ,value: data.money4
             }, function(value, index){
                 if (isNaN(value)) {
                     layer.msg("请输入数字！");
                     return;
                 }
                 layer.close(index);
                 var uinfo = { "money4" : value,"id":data.id }
                 //这里一般是发送修改的Ajax请求
                 $.ajax({
                     type: 'post',
                     url: baseUrl+"money/update",
                     data: uinfo,
                     async:false,
                     dataType: 'json',
                     success: function(res){
                         if(res.meta.code==200){
                             //加载层
                             var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                             setTimeout(function(){
                                 obj.update({
                                     money4: value
                                 });}, 1000);
                         }else{
                             //加载层
                             var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                         }
                     }
                 });
             });
         }else if(layEvent === 'edit5') { //编辑
             layer.prompt({
                 formType: 2
                 ,shadeClose:true
                 ,title: '请输出最低上庄金币'
                 ,value: data.money5
             }, function(value, index){
                 if (isNaN(value)) {
                     layer.msg("请输入数字！");
                     return;
                 }
                 layer.close(index);
                 var uinfo = { "money5" : value,"id":data.id }
                 //这里一般是发送修改的Ajax请求
                 $.ajax({
                     type: 'post',
                     url: baseUrl+"money/update",
                     data: uinfo,
                     async:false,
                     dataType: 'json',
                     success: function(res){
                         if(res.meta.code==200){
                             //加载层
                             var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                             setTimeout(function(){
                                 obj.update({
                                     money5: value
                                 });}, 1000);
                         }else{
                             //加载层
                             var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                         }
                     }
                 });
             });
         }else if(layEvent === 'edit6') { //编辑
             layer.prompt({
                 formType: 2
                 ,shadeClose:true
                 ,title: '请输出最低上庄金币'
                 ,value: data.money6
             }, function(value, index){
                 if (isNaN(value)) {
                     layer.msg("请输入数字！");
                     return;
                 }
                 layer.close(index);
                 var uinfo = { "money6" : value,"id":data.id }
                 //这里一般是发送修改的Ajax请求
                 $.ajax({
                     type: 'post',
                     url: baseUrl+"money/update",
                     data: uinfo,
                     async:false,
                     dataType: 'json',
                     success: function(res){
                         if(res.meta.code==200){
                             //加载层
                             var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                             setTimeout(function(){
                                 obj.update({
                                     money6: value
                                 });}, 1000);
                         }else{
                             //加载层
                             var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                             setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                         }
                     }
                 });
             });
         }
    });
    //第二个实例
    table.render({
        elem: '#demo1'
        ,height: "auto"
        ,method:"post"
        ,url: baseUrl+'money/findList' //数据接口
        ,page: false //开启分页
        ,where : {gameType:1}
        ,cols: [[ //表头
            {field: 'id', title: 'id',align:'center', sort:true}
            ,{field: 'money1', title: '筹码1',align:'center',event:"edit1"}
            ,{field: 'money2', title: '筹码2',align:'center',event:"edit2"}
            ,{field: 'money3', title: '筹码3',align:'center',event:"edit3"}
            ,{field: 'money4', title: '筹码4',align:'center',event:"edit4"}
            ,{field: 'money5', title: '筹码5',align:'center',event:"edit5"}
            ,{field: 'money6', title: '筹码6',align:'center',event:"edit6"}
            ,{field: 'roomGrade', title: '房间级别',align:'center',templet:function (d) {
                    if(d.roomGrade == 0){
                        return "<span style='color: #1E9FFF'>初级场</span>";
                    }else if (d.roomGrade ==1) {
                        return "<span style='color: #1E9FFF'>中级场</span>";
                    }else if (d.roomGrade ==2) {
                        return "<span style='color: #1E9FFF'>高级场</span>";
                    }
                }}
        ]]
        ,done:function(res,curr,count){
            // 隐藏列
            $(".layui-table-box").find("[data-field='id']").css("display","none");
        }
    });
    //监听工具条
    table.on('tool(test1)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        if(layEvent === 'edit1') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money1
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money1" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money1: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }else if(layEvent === 'edit2') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money2
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money2" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money2: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }else if(layEvent === 'edit3') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money3
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money3" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money3: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }else if(layEvent === 'edit4') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money4
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money4" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money4: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }else if(layEvent === 'edit5') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money5
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money5" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money5: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }else if(layEvent === 'edit6') { //编辑
            layer.prompt({
                formType: 2
                ,shadeClose:true
                ,title: '筹码'
                ,value: data.money6
            }, function(value, index){
                if (isNaN(value)) {
                    layer.msg("请输入数字！");
                    return;
                }
                layer.close(index);
                var uinfo = { "money6" : value,"id":data.id }
                //这里一般是发送修改的Ajax请求
                $.ajax({
                    type: 'post',
                    url: baseUrl+"money/update",
                    data: uinfo,
                    async:false,
                    dataType: 'json',
                    success: function(res){
                        if(res.meta.code==200){
                            //加载层
                            var index = layer.load(0, {shade: false,time:500} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:1,time:1000});index.closed}, 500);
                            setTimeout(function(){
                                obj.update({
                                    money6: value
                                });}, 1000);
                        }else{
                            //加载层
                            var index = layer.load(0, {shade: false,time:1000} ); //0代表加载的风格，支持0-2
                            setTimeout(function(){ layer.msg(''+res.meta.msg+'',{icon:2,time:1000});index.closed}, 1000);
                        }
                    }
                });
            });
        }
    });
})
